/*
 * CouponBO.java
 *
 * Created on March 5, 2007, 8:07 PM
 *
 * 
 */

package edu.byu.isys413.group1E.data;

import java.util.Calendar;
import java.util.Date;

/**Stores information about a coupon, which is applied to a revenue source
 * contained on a transaction line.  This object contains the relevant
 * revenue source ID, the amount or percentage of the coupon, the start and
 * expiration dates, and a description of the coupon.
 *
 * @author Travis Kulbeth
 */
public class CouponBO {
    
    private String CouponID;
    private String rsType;
    private double coupAmount = 0.0;
    private double coupPercent = 0.0;
    private String startDate;
    private String expireDate;
    private String description;
    boolean alreadyInDB;
    boolean isDirty;
    
    /** Creates a new instance of CouponBO */
    CouponBO() {
    }
    
    /** Creates a new instance of TransactionBO with an ID
     *@param CouponID contains the ID for this coupon
     */
    CouponBO(String CouponID) {
        setCouponID(CouponID);
        setIsDirty(true);
    }
    
    /** Checks to see if a coupon is valid according to the time frame
     *@return if this coupon is valid or not
     */
    public boolean isValid(){        
        //get the current date
        Calendar cal = Calendar.getInstance();
        Date today = cal.getTime();
        
        java.sql.Date start = java.sql.Date.valueOf(startDate);                 //retrieve the start date for the coupon
        java.sql.Date expire = java.sql.Date.valueOf(expireDate);               //retrieve the expiration date for the coupon
        
        //check if today's date (the date the coupon is being applied) is within
        //the time frame for the coupon, or is either on the start or expiration date
        if ((today.after(start) && today.before(expire)) || today.compareTo(start) == 0 || today.compareTo(expire) == 0){
            return true;
        }else{
            return false;
        }
    }
    
    /** Returns the couponID
     *@return CouponID
     */
    public String getCouponID() {
        return CouponID;
    }
    
    /** Sets the couponID
     *@param CouponID contains the id for this coupon
     */
    public void setCouponID(String CouponID) {
        setIsDirty(true);
        this.CouponID = CouponID;
    }
    
    /** Returns the Revenue Source ID that the coupon
     *applies to (will be changed to contain a revenue source type or specific product number for the next milestone).
     *@return RevSrcID that this coupon is associated with
     */
    public String getRevSrcType() {
        return rsType;
    }
    
    /** Sets the Revenue Source ID that the coupon
     *applies to.
     *@param RevSrcID contains the id for the Revenue Source that this coupon is associated with
     *(will be changed to contain a revenue source type or specific product number for the next milestone)
     */
    public void setRevSrcType(String rsType) {
        setIsDirty(true);
        this.rsType = rsType;
    }
    
    /** Returns the coupon amount (if the coupon is for
     * a certain dollar amount discount).
     *@return coupAmount
     */
    public double getCoupAmount() {
        return coupAmount;
    }
    
    /** Sets the coupon amount (if the coupon is for
     * a certain dollar amount discount).
     *@param coupAmount contains the amount that this coupon is for
     */
    public void setCoupAmount(double coupAmount) {
        setIsDirty(true);
        this.coupAmount = coupAmount;
    }
    
    /** Returns the coupon percentage (if the coupon is for
     * a certain percent discount).
     *@return coupPercent
     */
    public double getCoupPercent() {
        return coupPercent;
    }
    
    /** Sets the coupon percentage (if the coupon is for
     * a certain percent discount).
     *@param coupPercent contains the percentage that this coupon applies as a discount
     */
    public void setCoupPercent(double coupPercent) {
        setIsDirty(true);
        this.coupPercent = coupPercent;
    }
    
    /** Returns the coupon start date
     *@return startDate
     */
    public String getStartDate() {
        return startDate;
    }
    
    /** Sets the coupon start date
     *@param startDate contains the start date for this coupon
     */
    public void setStartDate(String startDate) {
        setIsDirty(true);
        this.startDate = startDate;
    }
    
    /** Returns the coupon expiration date
     *@return expireDAte
     */
    public String getExpireDate() {
        return expireDate;
    }
    
    /** Sets the coupon expiration date
     *@param expireDate contains the expiration date for this coupon
     */
    public void setExpireDate(String expireDate) {
        setIsDirty(true);
        this.expireDate = expireDate;
    }
    
    /** Returns the coupon description
     *@return description
     */
    public String getDescription() {
        return description;
    }
    
    /** Sets the coupon description
     *@param description contains a description of this coupon
     */
    public void setDescription(String description) {
       setIsDirty(true);
       this.description = description;
    }
    
    /** Sets the alreadyInDB variable to indicate that 
     * the information contained in this object has been stored in the database
     *@param is indicates if the object has already been stored in the DB
     */
    public void setAlreadyInDB(boolean is){
        setIsDirty(true);
        this.alreadyInDB = is;
    }

    /** Returns if the information contained in this object has already been stored in the database
     *@return alreadyInDB
     */
    public boolean isAlreadyInDB() {
        return alreadyInDB;
    }

    /** Returns if information has been changed within this object
     *@return isDirty
     */
    public boolean isIsDirty() {
        return isDirty;
    }

    /** Sets the variable isDirty to indicate that some information has been modified or changed
     *in this object
     *@param isDirty indicates if information has changed
     */
    public void setIsDirty(boolean isDirty) {
        this.isDirty = isDirty;
    }        
}
